package com.thon.entity.project;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thon.commons.config.Global;
import com.thon.entity.util.IdEntity;

/**
 * @file ProjectSchedule.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年11月8日 下午6:44:56
 * @description: 项目的执行方案实体
 */
@Entity
@Table(name="project_schedules")
@JsonIgnoreProperties(ignoreUnknown=true)
public class ProjectSchedule extends IdEntity{

	private static final long serialVersionUID = 5189328249059552489L;
	private Integer stage;
	private String content;
	private Date startDate;
	private Date endDate;
	private Project project;
	private ProjectBudget projectBudget;
	private String feedback;
	
	public Integer getStage() {
		return stage;
	}
	public void setStage(Integer stage) {
		this.stage = stage;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
	@DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss",timezone="GTM+08:00")
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	
	@DateTimeFormat(pattern="yyyy-MM-dd hh:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss",timezone="GTM+08:00")
	public Date getEndDate() {
		return endDate;
	}
	
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="project_id",nullable = false)
//	@JsonIgnore
	@JsonIgnoreProperties( value={"hibernateLazyInitializer","handler"})
	public Project getProject() {
		return project;
	}

    @JsonProperty
	public void setProject(Project project) {
		this.project = project;
	}
	
	@OneToOne(cascade = CascadeType.MERGE)
	@JoinColumn(name = "budget_id",unique = true)
	@JsonIgnore
	public ProjectBudget getProjectBudget() {
		return projectBudget;
	}
	public void setProjectBudget(ProjectBudget projectBudget) {
		this.projectBudget = projectBudget;
	}
	public String getFeedback() {
		if(!StringUtils.isBlank(feedback)){
			feedback = StringEscapeUtils.unescapeHtml4(feedback);
			feedback = feedback.replaceAll("src=\"../common/attachment/download/", "src=\""+Global.getConfig("img.url"));
		}
		return feedback;
	}
	public void setFeedback(String feedback) {
		this.feedback = feedback;
	}
	
}
